using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using TitanX;
/// <summary>
/// 表情通用类
/// </summary>




//一个小型的对象池，防止频繁的重复构建对象 ，我一直想做表情

public enum MoodType{warning,sad,happy}
public class MoodItem{
     [Header("图片")]
     public Sprite sprite;

    public MoodType moodType;

}


public class Mood :  SingletonGetMono<Player>
{
    [Header("小型的提示信息")]
    public GameObject tipMsgGm;

    public MoodItem[] moodItem;

    public Sprite[] sprites;

    public Dictionary<MoodType,Sprite> moodTypeDic=new Dictionary<MoodType,Sprite>(); 

    public List<GameObject>  moods =new List<GameObject>();

    void start(){

        
        foreach(MoodItem item in moodItem){
            moodTypeDic.Add(item.moodType, item.sprite);
        }

        for(int i=0;i<gameObject.transform.childCount;i++){
             moods.Add(gameObject.transform.GetChild(i).gameObject);
        }



    }



    void update(){



    }

    //展示表情
    public void Show(MoodType moodType,GameObject body ,float offset){
        
        GameObject mood=  availavleGameObjet();

        mood.GetComponent<Image>().sprite = moodTypeDic[moodType];
        mood.transform.position=body.transform.position;

        offset = body.transform.position.y+offset;
        mood.SetActive(true);

        Tweener tweener =  mood.transform.DOLocalMoveY(offset,0.3f);
        tweener.SetLoops(1, LoopType.Yoyo);
        tweener.Play();
        
        tweener.OnComplete(delegate {
                   mood.SetActive(false);
            });
    }    
    


    //展示小型的信息
    //提示信息
    public void TipMsg(string content,GameObject body ,float offset){
        //先移动到物体的位置
         tipMsgGm.SetActive(true);
        tipMsgGm.transform.position = body.transform.position;

        Tweener tweener =  transform.DOLocalMoveY(offset,0.5f).From(true);
        tweener.SetLoops(1, LoopType.Yoyo);
        tweener.Play();
        
         tweener.OnComplete(delegate {
                   tipMsgGm.SetActive(false);
            });

    }


    //取出可以用的对象
    public GameObject availavleGameObjet(){
        foreach(GameObject mood in moods){
            if(!mood.activeSelf){

                return mood;
            }

        }
        return null;

    }



}